package br.gov.cemaden.library.model.previsao;

import br.gov.cemaden.library.model.alerta.Agencia;
import br.gov.cemaden.library.repository.previsao.AquisicaoTempoRepository;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.Transient;

/**
 *
 * @author alan
 */
@Entity
@Table(name = "previsao_tempo_aquisicao", schema = "previsao")
@SequenceGenerator(name = "sequence", sequenceName = "previsao.previsao_tempo_aquisicao_sequence", schema = "previsao")
public class AquisicaoTempo implements Serializable {
    
    @Id
    @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
    @Column(name = "id_previsao_tempo_aquisicao")
    private Long id;
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    @Column(name = "aquisicao")
    private Date aquisicao;
    
    @ManyToOne(optional = false)
    @JoinColumn(name = "id_agencia", referencedColumnName = "id_agencia")    
    private Agencia agencia;
    
    @OneToMany(mappedBy = "aquisicao")
    private List<PrevisaoTempo> previsoes;
    
    @Transient
    private AquisicaoTempoRepository repository;
    
    public AquisicaoTempo(){
        
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getAquisicao() {
        return aquisicao;
    }

    public void setAquisicao(Date aquisicao) {
        this.aquisicao = aquisicao;
    }

    public Agencia getAgencia() {
        return agencia;
    }

    public void setAgencia(Agencia agencia) {
        this.agencia = agencia;
    }        

    public List<PrevisaoTempo> getPrevisoes() {
        return previsoes;
    }

    public void setPrevisoes(List<PrevisaoTempo> previsoes) {
        this.previsoes = previsoes;
    }

    public AquisicaoTempoRepository getRepository(EntityManager em) {
        if(repository == null){
            repository = new AquisicaoTempoRepository(em);
        }
        return repository;
    }

    public void setRepository(AquisicaoTempoRepository repository) {
        this.repository = repository;
    }        
    
    public AquisicaoTempo save(EntityManager em){
        return this.getRepository(em).persist(this);
    }
        
}
